package com.example.jinyu.protocol.model;

import com.alibaba.fastjson.JSON;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.MoccaPostRequest;
import com.example.jinyu.entry.BaseEntity;

public class BlogSaveRequest extends MoccaPostRequest<BaseEntity> {

    public BlogSaveRequest(String url, Listener<BaseEntity> listener, ErrorListener errorListener) {
        super(url, listener, errorListener);
    }

    @Override
    protected Response<BaseEntity> parseNetworkResponse(NetworkResponse response) {
        try {
            VolleyLog.e(new String(response.data, HttpHeaderParser.parseCharset(response.headers)
                    .toString()));
            return Response.success(
                    JSON.parseObject(
                            new String(response.data, HttpHeaderParser.parseCharset(
                                    response.headers).toString()), BaseEntity.class),
                    HttpHeaderParser.parseCacheHeaders(response));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error(new ParseError(e));
        }
    }

}
